// src/utils/api.js
import request from './request'

// 用户相关API
export const userApi = {
  login(data) {
    return request({
      url: '/api/v1/login/access-token',
      method: 'post',
      data
    })
  },

  logout() {
    return request({
      url: '/api/v1/logout',
      method: 'post'
    })
  },

  register(data) {
    return request({
      url: '/api/v1/users/signup',
      method: 'post',
      data,
      headers: {
        'Content-Type': 'application/json'
      }
    })
  },
  recoverPassword(email) {
    return request({
      url: `/api/v1/password-recovery/${email}`,
      method: 'post'
    })
  },
  resetPassword(data) {
    return request({
      url: '/api/v1/reset-password/',
      method: 'post',
      data,
      headers: {
        'Content-Type': 'application/json'
      }
    })
  },

  getUserInfo() {
    return request({
      url: '/api/v1/users/me',
      method: 'get'
    })
  },


   uploadAvatar(data) {
    return request({
      url: '/api/v1/users/me/avatar/upload',
      method: 'post',
      data,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  changePassword(data) {
    return request({
      url: '/api/v1/users/me/password',
      method: 'patch',
      data,
      headers: {
        'Content-Type': 'application/json'
      }
    })
  }

}

// 公司数据相关API
export const CampatydataApi = {
  getCampatyDataList() {
    return request({
      url: '/api/v1/companies/',
      method: 'get'
    })
  },

  getLevelsByCompanyId(companyId,jobId) {
    return request({
      url: `/api/v1/companies/${companyId}/levels?position_id=${jobId}&ship=0&limit=100`,
      method: 'get'
    })
  },

  getSalaryStatsByCompanyId(companyId) {
    return request({
      url: `/api/v1/companies/companies/${companyId}/salary-stats`,
      method: 'get'
    })
  }
}

// 薪酬数据相关API
export const SalariesdataApi = {
  getDataList(params) {
    return request({
      url: '/api/v1/salaries/',
      method: 'get',
      params
    })
  },

  getSalaryDetail(id) {
    return request({
      url: `/api/v1/salaries/${id}`,
      method: 'get'
    })
  },

  getSalaryByCompanyId(companyId, params) {
    return request({
      url: `/api/v1/salaries/company/${companyId}`,
      method: 'get',
      params
    })
  },

   getSalaryTotalByCompanyId(params) {
    return request({
      url: '/api/v1/companies/salary-stats-by-title',
      method: 'get',
      params
    })
  },

  submitSalary(data) {
    return request({
      url: '/api/v1/salaries/',
      method: 'post',
      data,
      headers: {
        'Content-Type': 'application/json'
      }
    })
  }
}

// 吐槽数据相关API
export const RoastApi = {
  getRoastList(params) {
    return request({
      url: '/api/v1/complaint/',
      method: 'get',
      params
    })
  },

  getRoastDetail(id) {
    return request({
      url: `/api/v1/complaint/${id}`,
      method: 'get'
    })
  },

  submitRoast(data) {
    return request({
      url: '/api/v1/complaint/',
      method: 'post',
      data,
      headers: {
        'Content-Type': 'application/json'
      }
    })
  }
}

// 职位数据相关API
export const JobApi = {
  getJobList(params) {
    return request({
      url: '/api/v1/jobs/jobs/',
      method: 'get',
      params
    })
  },
   getITCategories() {
    return request({
      url: '/api/v1/positions/category/IT',
      method: 'get'
    })
  }
}

// 职级预测相关API
export const PredictApi = {
  predictLevel(data) {
    return request({
      url: '/predict/api/v1/predict',
      method: 'post',
      data,
      headers: {
        'Content-Type': 'application/json'
      }
    })
  },
    // 从简历预测职级
  predictFromResume(data, isMultipart = false) {
    return request({
      url: '/predict/api/v1/predict_from_resume',
      method: 'post',
      data,
      headers: isMultipart ? {
        'Content-Type': 'multipart/form-data'
      } : {
        'Content-Type': 'application/json'
      }
    })
  },
   // 异步方式提交简历预测
  predictFromResumeAsync(data, isMultipart = false) {
    return request({
      url: '/predict/api/v1/predict_from_resume_async',
      method: 'post',
      data,
      headers: isMultipart ? {
        'Content-Type': 'multipart/form-data'
      } : {
        'Content-Type': 'application/json'
      }
    })
  },
    // 查询简历预测状态
  getPredictStatus(taskId) {
    return request({
      url: `/predict/api/v1/predict_from_resume_status/${taskId}`,
      method: 'get'
    })
  }
}